#ifndef SERVICE_CONNECTOR_H_INCLUDED
#define SERVICE_CONNECTOR_H_INCLUDED

#include <Core/Message.h>
#include <string>
#include <stdexcept>

namespace Core { namespace EndUserAPI {

class ServiceConnectorError : public std::runtime_error
{
public	:

	ServiceConnectorError(const std::string & err) : runtime_error(err) { }
};

/** Server connector provides simple wratpper above protocol + transport
 *  
 */
class ServiceConnector {
public 	:

	/** host with port 
	 *  Example: 127.0.0.1:80
	 */
	ServiceConnector(const char *hostPort);
	~ServiceConnector();	
	
	
	/** Evaluates search on servicein the file */
	void sendSearchMessage(const char *filename) throw (ServiceConnectorError);
	
	/** Evaluates search on server in the byte array */
	void sendSearchMessage(char *buf, std::size_t bufLen) throw (ServiceConnectorError);
	
	/** Gets next message */
    IMessage *getNextMessage();
	
	/** Interrupt processing and close connection
	 *  Return when processing is completed
	 *	After this call object can be safelly destroyed	 
	 */
	void close();

private	:
	
    /** Establish connecito with server and send ping
	 *  If server reply it considered that main request can be sent
	 */
	void establishConnection() throw (ServiceConnectorError);
	
	const std::string m_host;

    int mMaxMessage;
    int mCountMessage;
    IMessage *messageResult;

    void initDebug();

};


} } // namespace Core, EndUserAPI

#endif

